import React from 'react';
import GroupHeader from '@/components/GroupHeader';

const Layout: React.FC<{ children: any; history: any }> = (props) => {
  var options = [
    {title: '新闻列表', path: '/news/list'},
    {title: '编辑新闻', path: '/news/create', hide: true},
    {title: '查看新闻', path: '/news/show', hide: true},
    {title: '新闻编辑', path: '/news/update', hide: true},
    {title: '新闻分类', path: '/news/type', hide: false},
    {title: '新闻标签', path: '/news/tag', hide: false},
  ];
  var op = options.find((item) => item.path === props.history.location.pathname);
  if (!op) props.history.push(options[0].path);

  return (
    <>
      <GroupHeader
        {...props}
        onChage={(value) => {
          props.history.push(value.path);
        }}
        defaultValue={op ? op.title : options[0].title}
        prefix="新闻管理"
        options={options}
      ></GroupHeader>
      {props.children}
    </>
  );
};

export default Layout;
